<% layout('/layouts/default.html', {title: '出库单管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(outboundOrder.isNewRecord ? '新增出库单' : '编辑出库单')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${outboundOrder}" action="${ctx}/logistics/outboundorder/outboundOrder/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="outboundOrderId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单据编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="outboundOrderCode"  readonly="true" placeholder="自动生成" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="serviceOrderId" items="${listServiceOrder}" id="serviceOrderId"
                                itemLabel="serviceOrderCode" itemValue="serviceOrderId" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('仓库信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('车架号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="frameNumber" onchange="frameNumberChange()" items="${listFrameNumber}"
                                itemLabel="frameNumber" itemValue="frameNumber" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('车辆名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:hidden path="carId" id="carIdh"/>
                                <#form:select path="carId" items="${listCar}" id="carId" readonly="true"
                                itemLabel="carName" itemValue="carId" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('出库仓类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:hidden path="fromWarehouseType" id="fromWarehouseTypeh"/>
								<#form:select path="fromWarehouseType" id="fromWarehouseType" dictType="warehouse_xingzhi" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('出库仓')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:hidden path="fromWarehouse" id="fromWarehouseh"/>
                                <#form:select path="fromWarehouse" items="${listWarehouse}" id="fromWarehouse"
                                itemLabel="warehouseName" itemValue="warehouseId" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('目的仓类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="toWarehouseType" id="toWarehouseType" dictType="warehouse_xingzhi" blankOption="true" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('目的仓')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="toWarehouse" id="toWarehouse" itemLabel="warehouseName" items="${listWarehouse}"
                                itemValue="warehouseId" blankOption="true" class="form-control required" />
                            </div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('出库时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="date" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('物流信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('运输车队')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="transportFleet" dictType="erp_transport_team" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('车牌号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="carNumber" maxlength="50" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('司机姓名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="driverName" maxlength="50" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('司机联系方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="driverPhone" maxlength="50" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('附件信息')}</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${outboundOrder.id}" bizType="outboundOrder_file"
									uploadType="all" class="" readonly="false" preview="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('系统信息')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createDate" class="form-control" disabled="true"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createBy" class="form-control" disabled="true"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-unit">${text('相关单据')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('入库单')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:select path="inboundOrderCode" items="${listInboundOrder}"
                                itemLabel="inboundOrderCode" itemValue="inboundOrderId" blankOption="true" class="form-control" readonly="true" />
                            </div>
                        </div>
                    </div>
                </div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('logistics:outboundorder:outboundOrder:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>报关
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
</script>

<script>
    $("#serviceOrderId").change(function () {
        if ($(this).val()){
            $.ajax({
                type : "post",
                async : false,
                url : "${ctx}/order/serviceorder/serviceOrder/getOneById",
                data : {
                    'serviceOrderId' : $("#serviceOrderId").val()
                },
                dataType : "json",
                success : function(result) {
                    var list = result.serviceOrderDetailList;
                    $("#frameNumber").empty();
                    for (var i = 0; i < list.length; i++) {
                        var frameNumber = list[i].frameNumber;
                        if (frameNumber){
                            var option = $("<option>").attr({"value" : frameNumber}).text(frameNumber);
                            $("#frameNumber").append(option);
                        }
                    }
                    $("#frameNumber option:first").prop("selected", 'selected');
                    $("#frameNumber").change();
                }/*,
                error : function(json) {
                    js.alert("网络异常！");
                }*/
            });
        }else {
            $("#frameNumber").empty();
            $("#carId").val("").trigger('change');
            $("#carIdh").val("").trigger('change');
            $("#fromWarehouse").val("").trigger('change');
            $("#fromWarehouseh").val("").trigger('change');
            $("#fromWarehouseType").val("").trigger('change');
            $("#fromWarehouseTypeh").val("").trigger('change');
        }
    });

    function frameNumberChange() {
        var frameNumber = $("#frameNumber").val();
        if (frameNumber){
            $.ajax({
                type : "post",
                async : false,
                url : "${ctx}/order/serviceorder/serviceOrder/getOrderDetailByFrame",
                data : {
                    'frameNumber' :frameNumber
                },
                dataType : "json",
                success : function(result) {
                    $("#carId").val(result.carId).trigger('change');
                    $("#carIdh").val(result.carId).trigger('change');
                    $("#fromWarehouse").val(result.warehouseId).trigger('change');
                    $("#fromWarehouseh").val(result.warehouseId).trigger('change');
                    $("#fromWarehouseType").val(result.property).trigger('change');
                    $("#fromWarehouseTypeh").val(result.property).trigger('change');
                }/*,
                error : function(json) {
                    js.alert("网络异常！");
                }*/
            });
        }else {
            $("#carId").val("").trigger('change');
            $("#carIdh").val("").trigger('change');
            $("#fromWarehouse").val("").trigger('change');
            $("#fromWarehouseh").val("").trigger('change');
            $("#fromWarehouseType").val("").trigger('change');
            $("#fromWarehouseTypeh").val("").trigger('change');
        }

    }

    $("#toWarehouseType").change(function () {
        if ($(this).val()) {
            $.ajax({
                type: "post",
                async: false,
                url: "${ctx}/base/warehouse/twarehouse/listData",
                data: {
                    'property': $("#toWarehouseType").val()
                },
                dataType: "json",
                success: function (result) {
                    js.log(result)
                    var list = result.list;
                    $("#toWarehouse").empty();
                    for (var i = 0; i < list.length; i++) {
                        var warehouseId = list[i].id;
                        var warehouseName = list[i].warehouseName;
                        var option = $("<option>").attr({"value": warehouseId}).text(warehouseName);
                        $("#toWarehouse").append(option);
                    }
                    $("#toWarehouse option:first").prop("selected", 'selected');
                    $("#toWarehouse").change();
                }/*,
                error: function (json) {
                    js.alert("网络异常！");
                }*/
            });
        }else {
            $("#toWarehouse").empty();
        }
    });

</script>